import { Controller, Post, Get, Body } from '@nestjs/common';
import { MessageService } from './message.service';
import {
  SendMessageDto,
  GetMessagesDto,
  MarkReadDto,
} from './dto/create-message.dto';
import { Message } from './entities/message.entity';
import { Public } from 'src/auth/auth.decorator';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

@ApiTags('messages')
@Controller('messages')
export class MessageController {
  constructor(private readonly messageService: MessageService) {}

  @Public()
  @ApiOperation({ summary: '发送消息' })
  @ApiResponse({ status: 201, description: '消息发送成功', type: Message })
  @Post('send')
  async sendMessage(@Body() sendMessageDto: SendMessageDto) {
    return this.messageService.sendMessage(sendMessageDto);
  }

  @Public()
  @ApiOperation({ summary: '获取消息列表' })
  @ApiResponse({
    status: 200,
    description: '成功获取消息列表',
    type: [Message],
  })
  @Get('list')
  async getMessages(@Body() getMessagesDto: GetMessagesDto) {
    return this.messageService.getMessages(getMessagesDto);
  }

  @ApiOperation({ summary: '标记消息为已读' })
  @ApiResponse({
    status: 200,
    description: '消息标记已读成功',
  })
  @Public()
  @Post('mark-read')
  async markMessagesAsRead(@Body() markReadDto: MarkReadDto) {
    return this.messageService.markMessagesAsRead(markReadDto);
  }
}
